package com.itheima.duotai;

public class Demo01 {
    public static void main(String[] args) {
    /*    useAnimal(new Dog());
        useAnimal(new Cat());
        useAnimal(new Pig());*/
        Animal a = getAnimal();
        a.eat();

    }

    public static void useAnimal(Animal a){//这个方法可以接受任意animal 的子类对象
        a.eat();//执行 子类的方法
    }
 /*   public static void useDog(Dog dog){
        dog.eat();
    }
    public static void useCat(Cat cat){
        cat.eat();
    }*/
    public static Animal getAnimal(){
        //return new Dog();
        // return new Cat();
        return  new Pig();
    }
 /*   public static Dog  getDog(){
        return new Dog();
    }
    public static Cat  getCat(){
        return new Cat();
    }*/

}

abstract class  Animal{
    public void drink(){
        System.out.println("喝水");
    }
    public abstract void eat();
}

class Dog extends Animal{
    @Override
    public void eat() {
        System.out.println("狗吃狗粮");
    }
}
class Cat extends Animal{
    @Override
    public void eat() {
        System.out.println("猫吃老鼠");
    }
}
class Pig extends Animal{

    @Override
    public void eat() {
        System.out.println("猪吃白菜");
    }
}